package chapter23;

import java.util.List;

public class Chapter23Main {

    public static void main(String[] args) {
        System.out.println("----------------MST_kruskal-----------------------");

        MST_kruskal.EdgeNode a = new MST_kruskal.EdgeNode("a", 0);
        MST_kruskal.EdgeNode b = new MST_kruskal.EdgeNode("b", 1);
        MST_kruskal.EdgeNode c = new MST_kruskal.EdgeNode("c", 2);
        MST_kruskal.EdgeNode d = new MST_kruskal.EdgeNode("d", 3);
        MST_kruskal.EdgeNode e = new MST_kruskal.EdgeNode("e", 4);
        MST_kruskal.EdgeNode f = new MST_kruskal.EdgeNode("f", 5);
        MST_kruskal.EdgeNode g = new MST_kruskal.EdgeNode("g", 6);
        MST_kruskal.EdgeNode h = new MST_kruskal.EdgeNode("h", 7);
        MST_kruskal.EdgeNode i = new MST_kruskal.EdgeNode("i", 8);

        MST_kruskal.insert(a, new MST_kruskal.EdgeNode("b", 1), 4);
        MST_kruskal.insert(a, new MST_kruskal.EdgeNode("h", 7), 8);

        MST_kruskal.insert(b, new MST_kruskal.EdgeNode("a", 0), 4);
        MST_kruskal.insert(b, new MST_kruskal.EdgeNode("h", 7), 11);
        MST_kruskal.insert(b, new MST_kruskal.EdgeNode("c", 2), 8);

        MST_kruskal.insert(c, new MST_kruskal.EdgeNode("b", 1), 8);
        MST_kruskal.insert(c, new MST_kruskal.EdgeNode("i", 8), 2);
        MST_kruskal.insert(c, new MST_kruskal.EdgeNode("f", 5), 4);
        MST_kruskal.insert(c, new MST_kruskal.EdgeNode("d", 3), 7);

        MST_kruskal.insert(d, new MST_kruskal.EdgeNode("c", 2), 7);
        MST_kruskal.insert(d, new MST_kruskal.EdgeNode("f", 5), 14);
        MST_kruskal.insert(d, new MST_kruskal.EdgeNode("e", 4), 9);

        MST_kruskal.insert(e, new MST_kruskal.EdgeNode("d", 3), 9);
        MST_kruskal.insert(e, new MST_kruskal.EdgeNode("f", 5), 10);

        MST_kruskal.insert(f, new MST_kruskal.EdgeNode("e", 4), 10);
        MST_kruskal.insert(f, new MST_kruskal.EdgeNode("d", 3), 14);
        MST_kruskal.insert(f, new MST_kruskal.EdgeNode("c", 2), 4);
        MST_kruskal.insert(f, new MST_kruskal.EdgeNode("g", 6), 2);

        MST_kruskal.insert(g, new MST_kruskal.EdgeNode("f", 5), 2);
        MST_kruskal.insert(g, new MST_kruskal.EdgeNode("i", 8), 6);
        MST_kruskal.insert(g, new MST_kruskal.EdgeNode("h", 7), 1);

        MST_kruskal.insert(h, new MST_kruskal.EdgeNode("g", 6), 1);
        MST_kruskal.insert(h, new MST_kruskal.EdgeNode("b", 1), 11);
        MST_kruskal.insert(h, new MST_kruskal.EdgeNode("i", 8), 7);
        MST_kruskal.insert(h, new MST_kruskal.EdgeNode("a", 0), 8);

        MST_kruskal.insert(i, new MST_kruskal.EdgeNode("c", 2), 2);
        MST_kruskal.insert(i, new MST_kruskal.EdgeNode("g", 6), 6);
        MST_kruskal.insert(i, new MST_kruskal.EdgeNode("h", 7), 7);

        MST_kruskal.Graph G = new MST_kruskal.Graph();
        G.adjList.add(new MST_kruskal.VertexNode(a));
        G.adjList.add(new MST_kruskal.VertexNode(b));
        G.adjList.add(new MST_kruskal.VertexNode(c));
        G.adjList.add(new MST_kruskal.VertexNode(d));
        G.adjList.add(new MST_kruskal.VertexNode(e));
        G.adjList.add(new MST_kruskal.VertexNode(f));
        G.adjList.add(new MST_kruskal.VertexNode(g));
        G.adjList.add(new MST_kruskal.VertexNode(h));
        G.adjList.add(new MST_kruskal.VertexNode(i));
        G.numEdges = 25;
        G.numVertexes = 9;

        List<MST_kruskal.EdgeNode> edges = MST_kruskal.kruskal(G);
        edges.forEach(edgeNode -> {
            System.out.print(edgeNode.firstEdge.key + "->" + edgeNode.key);
            System.out.println();
        });

        System.out.println("----------------MST_prim-----------------------");

        MST_prim.EdgeNode a1 = new MST_prim.EdgeNode('a', 0);
        MST_prim.EdgeNode b1 = new MST_prim.EdgeNode('b', 1);
        MST_prim.EdgeNode c1 = new MST_prim.EdgeNode('c', 2);
        MST_prim.EdgeNode d1 = new MST_prim.EdgeNode('d', 3);
        MST_prim.EdgeNode e1 = new MST_prim.EdgeNode('e', 4);
        MST_prim.EdgeNode f1 = new MST_prim.EdgeNode('f', 5);
        MST_prim.EdgeNode g1 = new MST_prim.EdgeNode('g', 6);
        MST_prim.EdgeNode h1 = new MST_prim.EdgeNode('h', 7);
        MST_prim.EdgeNode i1 = new MST_prim.EdgeNode('i', 8);

        MST_prim.insert(a1, new MST_prim.EdgeNode('b', 1), 4);
        MST_prim.insert(a1, new MST_prim.EdgeNode('h', 7), 8);

        MST_prim.insert(b1, new MST_prim.EdgeNode('a', 0), 4);
        MST_prim.insert(b1, new MST_prim.EdgeNode('h', 7), 11);
        MST_prim.insert(b1, new MST_prim.EdgeNode('c', 2), 8);

        MST_prim.insert(c1, new MST_prim.EdgeNode('b', 1), 8);
        MST_prim.insert(c1, new MST_prim.EdgeNode('i', 8), 2);
        MST_prim.insert(c1, new MST_prim.EdgeNode('f', 5), 4);
        MST_prim.insert(c1, new MST_prim.EdgeNode('d', 3), 7);

        MST_prim.insert(d1, new MST_prim.EdgeNode('c', 2), 7);
        MST_prim.insert(d1, new MST_prim.EdgeNode('f', 5), 14);
        MST_prim.insert(d1, new MST_prim.EdgeNode('e', 4), 9);

        MST_prim.insert(e1, new MST_prim.EdgeNode('d', 3), 9);
        MST_prim.insert(e1, new MST_prim.EdgeNode('f', 5), 10);

        MST_prim.insert(f1, new MST_prim.EdgeNode('e', 4), 10);
        MST_prim.insert(f1, new MST_prim.EdgeNode('d', 3), 14);
        MST_prim.insert(f1, new MST_prim.EdgeNode('c', 2), 4);
        MST_prim.insert(f1, new MST_prim.EdgeNode('g', 6), 2);

        MST_prim.insert(g1, new MST_prim.EdgeNode('f', 5), 2);
        MST_prim.insert(g1, new MST_prim.EdgeNode('i', 8), 6);
        MST_prim.insert(g1, new MST_prim.EdgeNode('h', 7), 1);

        MST_prim.insert(h1, new MST_prim.EdgeNode('g', 6), 1);
        MST_prim.insert(h1, new MST_prim.EdgeNode('b', 1), 11);
        MST_prim.insert(h1, new MST_prim.EdgeNode('i', 8), 7);
        MST_prim.insert(h1, new MST_prim.EdgeNode('a', 0), 8);

        MST_prim.insert(i1, new MST_prim.EdgeNode('c', 2), 2);
        MST_prim.insert(i1, new MST_prim.EdgeNode('g', 6), 6);
        MST_prim.insert(i1, new MST_prim.EdgeNode('h', 7), 7);

        MST_prim.Graph G1 = new MST_prim.Graph();
        G1.adjList.add(new MST_prim.VertexNode(a1));
        G1.adjList.add(new MST_prim.VertexNode(b1));
        G1.adjList.add(new MST_prim.VertexNode(c1));
        G1.adjList.add(new MST_prim.VertexNode(d1));
        G1.adjList.add(new MST_prim.VertexNode(e1));
        G1.adjList.add(new MST_prim.VertexNode(f1));
        G1.adjList.add(new MST_prim.VertexNode(g1));
        G1.adjList.add(new MST_prim.VertexNode(h1));
        G1.adjList.add(new MST_prim.VertexNode(i1));
        G1.numEdges = 25;
        G1.numVertexes = 9;

        MST_prim.prim(G1);
        for (MST_prim.VertexNode u : G1.adjList) {
            if (u.firstEdge.pai != null) {
                System.out.println(u.firstEdge.pai.key + "->" + u.firstEdge.key);
            }
        }
    }

}
